package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminCategoryController")
@RequestMapping("/admin/category")
@Api(tags = "分类相关接口")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("/page")
    @ApiOperation("分类分页查询")
    public Result categoryList(CategoryPageQueryDTO categoryPageQueryDTO){
        return categoryService.categoryList(categoryPageQueryDTO);
    }

    @PostMapping
    @ApiOperation("新增分类")
    public Result saveCategory(@RequestBody CategoryDTO categoryDTO){
        return categoryService.saveCategory(categoryDTO);
    }

    @DeleteMapping
    @ApiOperation("根据id删除分类")
    public Result deleteById(String id){
        return categoryService.deleteById(id);
    }

    @PutMapping
    @ApiOperation("修改分类")
    public Result updateCategory(@RequestBody CategoryDTO categoryDTO){
        return categoryService.updateCategory(categoryDTO);
    }

    @PostMapping("/status/{status}")
    @ApiOperation("启用、禁用分类")
    public Result updateStatus(@PathVariable String status,String id){
        return categoryService.updateStatus(status,id);
    }

    @GetMapping("/list")
    @ApiOperation("根据类型查询分类")
    public Result getCategoriesByType(String type){
        return categoryService.getCategoriesByType(type);
    }
}
